package com.flower.service.impl;

import com.flower.mapper.UnitMapper;
import com.flower.model.entity.Unit;
import com.flower.service.UnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("all")
/**
 *@ClassName UnitServiceImpl
 *@Description TODO
 *@Author @O_o  GW__
 *@Date 2025/6/17 00:04
 *@Version 1.0
 */
@Service
public class UnitServiceImpl implements UnitService {
    @Autowired
    private UnitMapper unitMapper;
    @Override
    public List<Unit> getUnits() {
        List<Unit> units = unitMapper.getAllUnits();
        List<Unit> lists = new ArrayList();
        for (Unit unit : units) {
            if (unit.getUnitpid() == null){
                lists.add(unit);
            }
            else {
                for (Unit list : lists) {
                    List<Unit> Children = new ArrayList();
                    if (unit.getUnitpid().equals(list.getUnitsid())){
                        Children.add(unit);
                        list.setChildren(Children);
                    }

                }

            }
        }
        return lists;
    }
}
